import axios, { AxiosRequestConfig } from 'axios'

import type * as TDetail from '../AddOrEditTplRouteDrawer/interface'
import type * as TList from '../interface'
import './__mock__'

/** 获取路由模板列表 */
export const apiGetTplRouteList = async (
  req: TList.ITplRouteListReq,
  signal?: AxiosRequestConfig['signal'],
): Promise<TList.ITplRouteListRes> => {
  return axios.post(`/tmsapi/route_template/list`, req, { signal }).then(res => ({
    ...res.$data,
    records: res.$data.records || [],
  }))
}

/** 删除路由模板 */
export const apiDelTplRoute = async (routeId: string): Promise<void> => {
  await axios.post(`/tmsapi/route_template/del`, { routeId })
}

/** 获取路由模板详情 */
export const apiGetTplRouteDetail = async (routeId: string): Promise<TDetail.ITplRouteDetailRes> => {
  return axios.post(`/tmsapi/route_template/get`, { routeId }).then(res => res.$data)
}

/** 新增路由模板 */
export const apiAddTplRoute = async (req: TDetail.TSendValues): Promise<void> => {
  await axios.post(`/tmsapi/route_template/add`, req)
}

/** 编辑路由模板 */
export const apiEditTplRoute = async (req: TDetail.TSendValues): Promise<void> => {
  await axios.post(`/tmsapi/route_template/update`, req)
}
